package com.sskj.gocoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.util.ToastUtil;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.FabiDetailListBean;
import com.sskj.gocoin.m.bean.HaiPageBean;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.http.JsonConverter;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.v.fragment.FabiBuyAndSellDetailFragment;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;

import io.reactivex.Flowable;

public class FabiBuyDetailPresenter extends BasePresenter<FabiBuyAndSellDetailFragment> {
    public Flowable<List<FabiDetailListBean>> getList(int page, int size, boolean isBuy) {
        return OkGo.<HttpData<HaiPageBean<FabiDetailListBean>>>post(HttpConfig.BASE_URL + (isBuy ? HttpConfig.ORDER_LIST_BUY : HttpConfig.ORDER_LIST_SELL))
                .params("type", isBuy ? "pmma" : "sell")
                .params("p", page)
                .params("size", size)
                .converter(new JsonConverter<HttpData<HaiPageBean<FabiDetailListBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(haiPageBeanHttpData -> haiPageBeanHttpData.getData().getRes());
    }

    public void cancelPublishOrder(boolean isBuy, String id) {
        httpService.cancelFabiPublishOrder(isBuy, id)
                .tag(this)
                .execute(new JsonCallBack<com.sskj.common.base.HttpData>() {
                    @Override
                    public void onSuccess(Response<com.sskj.common.base.HttpData> response) {
                        com.sskj.common.base.HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.cancelSuccess();
                        }
                    }
                });
    }
}
